package com.quxian.chambercommerce.mobile_action;



import javax.servlet.http.HttpSession;

import com.quxian.chambercommerce.Model.Model;
import com.quxian.chambercommerce.base.BaseAction;
import com.quxian.chambercommerce.bean.ModleEntity;
import com.quxian.chambercommerce.bean.StaffInfoEntity;
import com.quxian.chambercommerce.service.LoginService;
import com.quxian.chambercommerce.util.StringUtil;

public class MobileLoginAction extends BaseAction{

	private static final long serialVersionUID = 1253164626342724654L;
	
	private LoginService loginService;
	
	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}
	
	private ModleEntity modleEntity;
	private StaffInfoEntity staffInfoEntity;
	private String userName;
	private String password;
	
	public LoginService getLoginService() {
		return loginService;
	}
	public ModleEntity getModleEntity() {
		return modleEntity;
	}
	public void setModleEntity(ModleEntity modleEntity) {
		this.modleEntity = modleEntity;
	}
	public StaffInfoEntity getStaffInfoEntity() {
		return staffInfoEntity;
	}
	public void setStaffInfoEntity(StaffInfoEntity staffInfoEntity) {
		this.staffInfoEntity = staffInfoEntity;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	/**
	 * version用于区分是从那个平台登录，做报表时需要
	 * 1：web
	 * 2:boss客户端
	 * 3：staff客户端
	 */
	public String execute() {
		Model json = new Model();
		try{
			System.out.println("=======login======="+userName+"==="+password);
			if(StringUtil.isEmpty(userName)) {
				createErrorJson("请输入用户名");
				return SUCCESS;
			}
			
			if(StringUtil.isEmpty(password)) {
				createErrorJson("请输入密码");
				return SUCCESS;
			}
			
			staffInfoEntity = loginService.login(userName, password);
			json.setData(staffInfoEntity);
			json.setStatus("SUCCESS");
			json.setErrorMessage("");
			setJsonModel(json);
			
			HttpSession session = request.getSession();
			session.setAttribute("user",staffInfoEntity);
			
		} catch (Exception e) {
			createErrorJson(e.getMessage());
		}
		return SUCCESS;
	}
}
